#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int cmpchar(const void *p1, const void *p2)
{
    return *((char *)p1) - *((char *)p2);
}

int main()
{
    int num_a = 0;
    int n = 0;
    int num = 0;
    while (scanf("%d ", &n) != EOF)
    {
        int count = 0;
        char str[100];
        gets(str);
        qsort(str, n, sizeof(str[0]), cmpchar);
        for (int i = 1; i < n; i++)
        {
            if (str[i] == str[i + 1] && str[i] == str[i + 2])
            {
                count = count + str[i] - 97;
            }
            else if (str[i] == str[i + 1] && str[i] != str[i + 2])
            {
                count = count + (str[i] - 97) * 2;
            }
        }
        for (int j = 0; j < n; j++)
        {
            if (str[j] == 'a')
            {
                num_a++;
            }
        }
        printf("%d", count * num_a);
    }
    return 0;
}